package rabbitmq.work;

import com.rabbitmq.client.Channel;
import com.rabbitmq.client.Connection;
import com.rabbitmq.client.ConnectionFactory;
import rabbitmq.constants.Constants;
import rabbitmq.utils.WorkUtils;

import java.io.IOException;
import java.util.concurrent.TimeoutException;

public class Producer {
    public static void main(String[] args) throws IOException, TimeoutException {
        ConnectionFactory factory = WorkUtils.createConnectionFactory();
        //1.建立连接
        Connection connection = factory.newConnection();
        //2.开启信道
        Channel channel = connection.createChannel();
        //3.声明交换机，队列
        channel.queueDeclare(Constants.WORK_QUEUE,true,false,false,null);
        //4.发送信息
        for (int i = 0; i < 10; i++){
            String msg = "hello workQueue " + i;
            channel.basicPublish(Constants.WORK_EXCHANGE,Constants.WORK_QUEUE,null,msg.getBytes());
        }
        System.out.println("发生消息成功~");
        //5.释放资源
        channel.close();
        connection.close();
    }
}
